package cn.hl.sfzy.controller;

import cn.hl.sfzy.entity.Company;
import cn.hl.sfzy.service.CompanyService;
import cn.hl.sfzy.util.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName CompanyController
 * @Description TOOO
 * @Author Lilysi
 * @Date 2024//10//25//17:36
 * @Version 1.0
 */
@RestController
@CrossOrigin
@RequestMapping("/Company")
public class CompanyController {
    @Autowired
    private CompanyService companyService;
    @GetMapping
    public Result pageSelect(@RequestParam(required = false,defaultValue = "1") int pageNum, @RequestParam(required = false,defaultValue = "5") int pageSize, Company company) {
        PageInfo<Company> byPage = companyService.findByPage(pageNum, pageSize, company);
        return Result.success(byPage);
    }
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        int delete = companyService.delete(id);
        return Result.success("删除成功");
    }
    @PostMapping
    public Result insert(@RequestBody Company company) {
        int insert = companyService.insert(company);
        return Result.success(insert);
    }


    @PutMapping
    public Result update(@RequestBody Company company) {
        int update = companyService.update(company);
        return Result.success(update);
    }

    @GetMapping("/find")
    public Company findById() {
        Company company = companyService.find();
        return company;
    }
}
